<template>
  <div class="page">
    <h4 style="margin-left: 3px">基本信息筛选</h4>
    <el-row :gutter="20">
      <el-form id="formbox" ref="formInline" :inline="true" :model="formInline">
        <el-col :span="8" class="mb20">
          <el-form-item label="姓名 :" prop="name">
            <el-input
              clearable
              v-model="formInline.name"
              placeholder="请输入姓名"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="证件号码 :" prop="cardNumber">
            <el-input
              clearable
              v-model="formInline.cardNumber"
              placeholder="请输入证件号码"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="录入人 :" prop="inputPerson">
            <el-input
              clearable
              v-model="formInline.inputPerson"
              placeholder="请输入录入人"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="检查医生 :" prop="exaDoctor">
            <el-input
              clearable
              v-model="formInline.exaDoctor"
              placeholder="请输入检查医生"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="采集状态 :" prop="collectionStatus">
            <el-select
              clearable
              v-model="formInline.collectionStatus"
              placeholder="请选择采集状态"
            >
              <el-option label="采集成功" value="采集成功"></el-option>
              <el-option label="采集失败" value="采集失败"></el-option>
              <el-option label="未采集" value="未采集"></el-option>
              <!-- <el-option label="正在采集" value="正在采集"></el-option> -->
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="回填状态 :" prop="backFillingStatus">
            <el-select
              clearable
              v-model="formInline.backFillingStatus"
              placeholder="请选择回填状态"
            >
              <el-option label="回填成功" value="回填成功"></el-option>
              <el-option label="回填失败" value="回填失败"></el-option>
              <el-option label="未回填" value="未回填"></el-option>
              <el-option label="已人工回填" value="已人工回填"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="回填类型 :" prop="backFillingType">
            <el-select
              v-model="formInline.backFillingType"
              placeholder="请选择回填类型"
              @change="handleBackChange"
            >
              <el-option label="健康体检表" value="健康体检表"></el-option>
              <el-option label="用药情况" value="用药情况"></el-option>
              <el-option label="辅助检查" value="辅助检查"></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8" class="mb20">
          <el-form-item label="人群分类 :" prop="populationCategory">
            <el-select
              multiple
              clearable
              v-model="formInline.populationCategory"
              placeholder="请选择人群分类"
            >
              <!-- @change="handleSelectChange1" -->
              <!-- <el-option label="全选" value="全选"></el-option> -->
              <el-option label="高血压" value="高血压"></el-option>
              <el-option label="糖尿病" value="糖尿病"></el-option>
              <el-option label="老年人" value="老年人"></el-option>
              <el-option label="其他" value="其他"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="已回填辅助检查 :" prop="backHuiTianStatus">
            <el-select
              multiple
              clearable
              v-model="formInline.backHuiTianStatus"
              placeholder="请选择已回填辅助检查"
            >
              <!-- @change="handleSelectChange" -->
              <!-- <el-option label="全选" value="全选"></el-option> -->
              <el-option label="血液检验" value="血液检验"></el-option>
              <el-option label="尿液检验" value="尿液检验"></el-option>
              <el-option label="心电图" value="心电图"></el-option>
              <el-option label="腹部B超" value="腹部B超"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="体检日期 :" prop="followTime">
            <el-date-picker
              :disabled-date="disableFutureDates"
              v-model="formInline.followTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              size="large"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="创建日期 :" prop="startTime">
            <el-date-picker
              :disabled-date="disableFutureDates"
              v-model="formInline.startTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              size="large"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20" prop="nextFollowTime">
          <el-form-item label="下次年检日期 :">
            <el-date-picker
              v-model="formInline.nextFollowTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              size="large"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8" class="mb20">
          <el-form-item label="质控类型 :" prop="result">
            <el-select v-model="formInline.result" placeholder="请选择质控类型">
              <el-option label="全部" value=""></el-option>
              <el-option label="告警类" value="告警类"></el-option>
              <el-option label="错误类" value="错误类"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" class="form-button">
          <el-form-item>
            <el-button type="primary" @click="getList()">查询</el-button>
            <el-button @click="onReset('formInline')">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-row class="popover-container">
      <el-popover
        placement="left"
        width="200"
        trigger="click"
        class=""
        @hide="isPopOpen = false"
      >
        <!-- v-model="isPopOpen" -->
        <div class="popover-item-list">
          <h3>任务进度</h3>
          <div class="item-titel gradient-text">并发数:{{ concurrency }}台</div>
          <div class="item-titel gradient-text">
            数据采集中:{{ collecting }}条
          </div>
          <div class="item-titel gradient-text">
            更新健康体检中:{{ updateHealthCheckup }}条
          </div>
          <div class="item-titel gradient-text">
            更新辅助检查中:{{ updateAuxiliary }}条
          </div>
          <div class="item-titel gradient-text">
            更新用药情况中:{{ updateDrug }}条
          </div>
        </div>

        <!-- <div class="arrow-container" slot="reference">
            <span class="arrow" :class="{ rotate: isPopOpen }">«</span>
          </div> -->
        <template #reference>
          <div class="arrow-container popover-content-list" slot="reference">
            <span
              class="arrow"
              :class="{ rotate: isPopOpen }"
              @click="isPopOpen = !isPopOpen"
              >«</span
            >
          </div>
        </template>
      </el-popover>
    </el-row>
    <div class="table-container">
      <el-col :span="24"
        ><h4 style="margin-left: 3px">体检记录 (共{{ total }}条)</h4></el-col
      >
      <el-col :span="24" style="display: flex">
        <el-col :span="4">
          <div class="table-btn">
            <div>
              <el-checkbox
                @change="checkedAllChange"
                v-model="checkedAll"
                :label="'全选'"
                :disabled="tableData.length == 0"
              />
            </div>
            <div style="margin-right: 10px">
              <label
                >已选择<el-text type="primary">{{
                  checkedAll == true ? selectionCount : multipleSelection.length
                }}</el-text
                >条</label
              >
            </div>
          </div>
        </el-col>
        <el-col :span="20" class="tr" v-if="healthExaminationForm">
          <router-link to="/physicals/health" style="margin-right: 10px">
            <el-button type="primary">新增体检</el-button>
          </router-link>
          <el-button
            type="primary"
            :disabled="multipleSelection.length === 0"
            @click="manualBackfilling()"
            >已人工回填</el-button
          >
          <el-button
            style="width: 87.6px"
            type="primary"
            :disabled="multipleSelection.length === 0"
            @click="exportSelect()"
            >导出</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="danger"
            @click="removeSelect()"
            style="width: 87.6px; color: #fff"
            >删除</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="testSt()"
            >数据采集</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="showUpload()"
            >更新健康体检表</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="auxiliaryUpload()"
            >更新辅助检查</el-button
          >
          <!-- <el-button type="success" @click="downloadTemp()"
            >下载导入模版</el-button
          > -->
        </el-col>
        <el-col :span="20" class="tr" v-if="medicationSituation">
          <el-button
            style="width: 87.6px"
            type="primary"
            @click="importSelect()"
            >导入</el-button
          >
          <!-- <el-button
            style="width: 87.6px"
            type="primary"
            :disabled="multipleSelection.length === 0"
            @click="exportSelect()"
            >导出</el-button
          > -->
          <el-button
            :disabled="multipleSelection.length === 0"
            type="danger"
            @click="removeSelects()"
            style="width: 87.6px; color: #fff"
            >删除</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="testDrug()"
            >数据采集</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="showDrug()"
            >更新用药情况</el-button
          >
          <el-button type="success" @click="downloadTemp()"
            >下载导入模版</el-button
          >
        </el-col>
        <el-col :span="20" class="tr" v-if="auxiliaryInspection">
          <el-button
            style="width: 87.6px"
            type="primary"
            @click="importSelect()"
            >导入</el-button
          >
          <!-- <el-button
            style="width: 87.6px"
            type="primary"
            :disabled="multipleSelection.length === 0"
            @click="exportSelect()"
            >导出</el-button
          > -->
          <el-button
            :disabled="multipleSelection.length === 0"
            type="danger"
            @click="removeSelects()"
            style="width: 87.6px; color: #fff"
            >删除</el-button
          >
          <el-button
            :disabled="multipleSelection.length === 0"
            type="primary"
            @click="auxiliaryUpload()"
            >更新辅助检查</el-button
          >
          <el-button type="success" @click="downloadTemp()"
            >下载导入模版</el-button
          >
        </el-col>
      </el-col>
    </div>
    <el-table
      ref="multipleTableRef"
      :data="tableData"
      border
      :default-sort="{ prop: 'date', order: 'descending' }"
      style="width: 100%"
      tooltip-effect="light"
      row-key="id"
      @selection-change="handleSelectionChange"
      :header-cell-class-name="setClassName"
      max-height="470px"
    >
      <el-table-column
        type="selection"
        :reserve-selection="true"
        width="55"
        align="center"
      />
      <el-table-column
        type="index"
        label="序号"
        width="80"
        align="center"
        fixed="left"
      />
      <el-table-column
        prop="name"
        label="姓名"
        align="center"
        fixed="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="cardType"
        label="证件类型"
        align="center"
        width="180"
   
        show-overflow-tooltip
      />

      <el-table-column
        prop="cardNumber"
        label="证件号码"
        align="center"
        width="180"
        show-overflow-tooltip
      />

      <el-table-column
        prop="exaTime"
        label="体检日期"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        prop="backFillingType"
        label="回填类型"
        align="center"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="healthExaminationForm"
        prop="personCategory"
        label="人群分类"
        align="center"
        width="180"
        show-overflow-tooltip
      />

      <el-table-column
        prop="collectStatus"
        label="采集状态"
        align="center"
        width="100"
        show-overflow-tooltip
      >
      <template #default="{ row }">
            <el-popover
              v-if="row.collectStatus === '采集失败'"
              :content="row.collectErrorInfo"
              trigger="hover"
              placement="top"
            >
              <template #reference>
                <span>
                  {{ row.collectStatus }}
                </span>
              </template>
            </el-popover>
            <span v-else>
              {{ row.collectStatus }}
            </span>
          </template>
    
    </el-table-column>
      <el-table-column
        prop="backFillingStatus"
        label="回填状态"
        align="center"
        width="100"
        show-overflow-tooltip
      >
      <template #default="{ row }">
            <el-popover
              v-if="row.backFillingStatus === '回填失败'"
              :content="row.backFillingErrorInfo"
              trigger="hover"
              placement="top"
            >
              <template #reference>
                <span>
                  {{ row.backFillingStatus }}
                </span>
              </template>
            </el-popover>
            <span v-else>
              {{ row.backFillingStatus }}
            </span>
          </template>
      </el-table-column>
      <el-table-column
        v-if="healthExaminationForm || auxiliaryInspection"
        prop="backHuitianStatus"
        label="已回填辅助检查"
        align="center"
        width="180"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        v-if="healthExaminationForm"
        prop="qcAlertClass"
        label="质控-告警类"
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span style="color: #f5c400">{{ scope.row.qcAlertClass }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="healthExaminationForm"
        prop="qcErrorClass"
        label="质控-错误类"
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <span style="color: red">{{ scope.row.qcErrorClass }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="medicationSituation"
        prop="healthCheckupMedicationSituation"
        label="用药情况"
        align="center"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        prop="inputPerson"
        label="录入人"
        align="center"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="healthExaminationForm"
        prop="exaDoctor"
        label="体检医生"
        align="center"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        prop="createTime"
        align="center"
        width="180"
        label="创建时间"
        show-overflow-tooltip
      />

      <el-table-column
        v-if="healthExaminationForm || medicationSituation"
        prop="importTime"
        label="诊疗信息导入时间"
        width="180"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        prop="nextYearExaTime"
        align="center"
        width="180"
        label="下次年检时间"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="gender"
        label="性别"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="birthday"
        label="出生日期"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="phoneNumber"
        label="联系电话"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="contacts"
        label="联系人姓名"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="contactsNumber"
        label="联系人电话"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="address"
        label="现住址"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="auxiliaryInspection"
        prop="domicileAddress"
        label="户籍地址"
        align="center"
        width="180"
        show-overflow-tooltip
      />

      <el-table-column
        show-overflow-tooltip
        label="操作"
        width="180"
        align="center"
        fixed="right"
      >
        <template #default="scope">
          <el-button
            v-show="formInline.backFillingType !== '辅助检查'"
            text=""
            size="small"
            type="primary"
            @click="openEditResidents(scope.row)"
            >编辑</el-button
          >
          <el-button
            text=""
            size="small"
            type="danger"
            @click="delFollow(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-col
      :span="24"
      style="display: flex; justify-content: end; margin-bottom: 50px"
    >
      <el-pagination
        v-if="this.total > 0"
        v-model:currentPage="this.currentPage"
        v-model:page-size="this.pageSize"
        :total="this.total"
        :page-sizes="[10, 20, 50, 100, 500]"
        class="new-pagination"
        small
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes, prev, pager, next, jumper"
      />
    </el-col>
    <EditDialog
      ref="editDialogRef"
      :dialogObj="dialogObj"
      @update="handerUpdate"
    />
    <HealDialog
      ref="healDialogRef"
      :dialogObj="healogObj"
      @changeHeal="updateHeal"
    ></HealDialog>
    <DrugDialog
      ref="drugDialogRef"
      :state="state"
      @changeDrug="handleChangeDD"
    ></DrugDialog>
    <!--@reloadTable="handleQuery" -->
  </div>
</template>

<script lang="ts">
import { getUserName } from "@/utils/common";
import { ElMessage } from "element-plus";
import MenuCheck from "@/components/menu-check/index.vue";
import DeptList from "@/components/dept-list/index.vue";
import EditDialog from "@/pages/examples/pe/components/editDialog.vue";
import DrugDialog from "@/pages/examples/pe/components/drugDialog.vue";
import HealDialog from "@/pages/examples/pe/components/healDialog.vue";
const disableFutureDates = (time) => time > new Date();
import http from "@/utils/request";

export default {
  components: {
    MenuCheck,
    DeptList,
    EditDialog,
    DrugDialog,
    HealDialog,
  },
  emits: ["update"],

  data() {
    return {
      isPopOpen: false,
      concurrency: 0,
      collecting: 0,
      updateHealthCheckup: 0,
      updateDrug: 0,
      updateAuxiliary: 0,
      selfCareAssessmentVisible: false,
      //记录条数
      total: 1,
      //每页条数
      pageSize: 10,
      //当前页码
      currentPage: 1,
      //选择条数
      selectionCount: 0,
      //选择数组
      multipleSelection: [],
      //全选状态
      checkedAll: false,
      dialogObj: {
        //弹窗标题
        editResidentsTitle: "",
        //弹窗是否显示
        isDialogVisible: false,
        //弹窗数据
        DialogDate: {},
      },
      healogObj: {
        //弹窗标题
        editResidentsTitle: "",
        //弹窗是否显示
        isDialogVisible: false,
        //弹窗数据
        DialogDate: {},
      },
      state: {
        dialogUploadVisible: false,
        accept: ".xlsx,.csv",
        url: "",
      },
      //表格数据
      tableData: [],
      ruleform: {
        name: "",
      },
      formInline: {
        //姓名
        name: "",

        //身份证
        cardNumber: "",

        //录入人
        inputPerson: "",

        // 检查医生
        exaDoctor: "",

        // 采集状态
        collectionStatus: "",

        // 回填状态
        backFillingStatus: "",
        backFillingType: "健康体检表",
        // 人群分类
        populationCategory: [],
        // 已回填辅助检查
        backHuiTianStatus: [],

        // 体检日期
        followTime: "",
        //创建日期
        startTime: "",
        // 下次体检日期
        nextFollowTime: "",

        // 检验开始日期
        exaBeginTime: "",

        // 检验结束日期
        exaEndTime: "",

        // 导入开始日期/创建日期
        importBeginTime: "",

        // 导入结束日期/创建日期
        importEndTime: "",

        // 下次年检开始日期
        nextYearBeginExaTime: "",

        // 下次年检结束日期
        nextYearEndExaTime: "",
        // 质控类型
        result: "",
      },
    };
  },
  methods: {
    disableFutureDates,
    handleChangeDD(newValue, oldValue) {
      this.state.dialogUploadVisible = newValue;
      this.getList();
    },
    togglePopover() {
      this.isPopOpen = !this.isPopOpen;
    },
    //队列显示方法
    searchQuest() {
      http.get("/health/searchQuest").then((res) => {
        if (res.code == 200) {
          this.concurrency = res.data.concurrency;
          this.collecting = res.data.collecting;
          this.updateHealthCheckup = res.data.updateHealthCheckup;
          this.updateDrug = res.data.updateDrug;
          this.updateAuxiliary = res.data.updateAuxiliary;
        }
      });
    },
    updateHeal() {
      this.getList();
    },
    importSelect() {
      this.state.dialogUploadVisible = true;
      this.state.url = "/api/v1.0/health/importExcel";
    },
    downloadTemp() {
      http.get("/assist/initializeExcelTemplate/healthCheckUp").then((res) => {
        //@ts-ignore
        if (res.code === 200) {
          window.open(res.data);
        }
      });
    },
    removeSelect() {
      const idList = this.multipleSelection.map((item) => item.id);
      this.$confirm("是否确定删除已选择数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          http.post("/health/deleteById/", idList).then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              //@ts-ignore
              ElMessage.success(res.message);
              this.multipleSelection = [];
              this.checkedAll = false;
              this.getList();
              this.$refs.multipleTableRef!.clearSelection();
            }
          });
        })
        .catch(() => {});
    },
    removeSelects() {
      const idList = this.multipleSelection.map((item) => item.id);
      this.$confirm("是否确定删除已选择数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          http.post("/health/deleteById", idList).then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              //@ts-ignore
              ElMessage.success(res.message);
              this.multipleSelection = [];
              this.checkedAll = false;
              this.getList();
              this.$refs.multipleTableRef!.clearSelection();
            }
          });
        })
        .catch(() => {});
    },

    //更新数据
    handerUpdate() {
      this.getList();
    },
    handleBackChange() {
      this.getList();
      this.checkedAll = false;
      this.$refs.multipleTableRef!.clearSelection();
      this.multipleSelection = [];
    },

    handleSelectChange1(selected) {
      if (selected.includes("全选")) {
        this.formInline.populationCategory = ["全选"];
      } else if (this.formInline.populationCategory.includes("全选")) {
        this.formInline.populationCategory = selected.filter(
          (item) => item !== "全选"
        );
      }
    },
    handleSelectChange(selected) {
      if (selected.includes("全选")) {
        this.formInline.backHuiTianStatus = ["全选"];
      } else if (this.formInline.backHuiTianStatus.includes("全选")) {
        this.formInline.backHuiTianStatus = selected.filter(
          (item) => item !== "全选"
        );
      }
    },

    //更新老年人表
    //查询接口
    getList() {
      const requestData = { page: this.currentPage, size: this.pageSize };
      for (const key in this.formInline) {
        if (this.formInline[key]) {
          requestData[key] = this.formInline[key];
        }
      }
      //@ts-ignore
      if (requestData.followTime) {
        //@ts-ignore
        requestData.exaBeginTime = requestData.followTime[0];
        //@ts-ignore
        requestData.exaEndTime = requestData.followTime[1];
        //@ts-ignore
        delete requestData.followTime;
      }
      //@ts-ignore
      if (requestData.startTime) {
        //@ts-ignore
        requestData.importBeginTime = requestData.startTime[0];
        //@ts-ignore
        requestData.importEndTime = requestData.startTime[1];

        //@ts-ignore
        delete requestData.startTime;
      }
      //@ts-ignore
      if (requestData.nextFollowTime) {
        //@ts-ignore
        requestData.nextYearBeginExaTime = requestData.nextFollowTime[0];
        //@ts-ignore
        requestData.nextYearEndExaTime = requestData.nextFollowTime[1];

        //@ts-ignore
        delete requestData.nextFollowTime;
      }
      //@ts-ignore
      if (requestData.populationCategory.length == 0) {
        //@ts-ignore
        delete requestData.populationCategory;
      }
      //@ts-ignore
      if (requestData.backHuiTianStatus.length == 0) {
        //@ts-ignore
        delete requestData.backHuiTianStatus;
      }

      http.post("/health/getList", requestData).then((res) => {
        //@ts-ignore
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.total = res.data.total;
        }
      });
    },

    //重置搜索
    onReset(formName) {
      this.$refs[formName].resetFields();
      this.formInline.startTime = "";
      this.formInline.nextFollowTime = "";
      this.currentPage = 1;
    },

    //打开编辑页
    openEditResidents(row) {
      if (this.healthExaminationForm) {
        this.dialogObj.editResidentsTitle = "编辑";
        http.get(`/health/getHealthById/${row.id}`).then((res) => {
          //@ts-ignore
          if (res.code == 200) {
            //@ts-ignore
            if (res.data) {
              this.dialogObj.DialogDate = res.data;
              this.dialogObj.isDialogVisible = true;
            }
          }
        });
      } else if (this.medicationSituation) {
        this.healogObj.editResidentsTitle = "编辑用药情况";
        http.get(`/health/getHealthById/${row.id}`).then((res) => {
          //@ts-ignore
          if (res.code == 200) {
            //@ts-ignore
            if (res.data) {
              this.healogObj.DialogDate = res.data;
              this.healogObj.isDialogVisible = true;
            }
          }
        });
      }

      // this.dialogObj.DialogDate = row;
    },

    //删除随访
    delFollow(row) {
      const idList = [row.id];
      if (this.healthExaminationForm) {
        this.$confirm(`确定删除${row.name}的体检记录吗？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            http.post("/health/deleteById", idList).then((res) => {
              //@ts-ignore
              if (res.code == 200) {
                //@ts-ignore
                ElMessage.success(res.message);
                this.getList();
                this.$refs.multipleTableRef!.clearSelection();
              } else {
              }
            });
          })
          .catch(() => {});
      } else {
        this.$confirm(`确定删除当前数据吗？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            http.post("/health/deleteById", idList).then((res) => {
              //@ts-ignore
              if (res.code == 200) {
                //@ts-ignore
                ElMessage.success(res.message);
                this.$refs.multipleTableRef!.clearSelection();
                this.getList();
              } else {
              }
            });
          })
          .catch(() => {});
      }
    },
    // 改变页面容量
    handleSizeChange(val: number) {
      this.pageSize = val;
      this.getList();
    },

    // 改变页码序号
    handleCurrentChange(val: number) {
      this.currentPage = val;
      this.getList();
    },
    checkSelectable() {
      return this.checkedAll != true;
    },
    checkedAllChange() {
      if (this.checkedAll == true) {
        this.selectionCount = this.tableData.length;
        console.log(this.selectionCount);

        this.tableData.forEach((row: any) => {
          this.$refs.multipleTableRef!.toggleRowSelection(row, true);
        });
      } else {
        this.selectionCount = 0;
        this.$refs.multipleTableRef!.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if (val.length == this.total || val.length == this.pageSize) {
        this.checkedAll = true;
        this.selectionCount = val.length;
      } else {
        this.checkedAll = false;
        this.selectionCount = 0;
      }

      // console.log("val",val);
      // if(multipleSelection.value.length==0){
      //   checkedAll.value=false;
      // }
    },
    setClassName({ column }) {
      return this.checkedAll == true ? "all-disabled" : "";
    },
    //人工回填
    manualBackfilling() {
      const upArr = [];
      this.multipleSelection.forEach((item) => {
        upArr.push(
          item.id,
        );
      });
      const arrTrue = this.multipleSelection.every((item) => {
        return item.collectStatus !== "未采集";
      });
      const arrTrue2 = this.multipleSelection.every((item) => {
        return item.backFillingStatus !== "回填成功";
      });

      if (arrTrue && arrTrue2) {
        http
          .post("/health/manuallyBackfilled", upArr)
          .then((res) => {
            if (res.code == 200) {
              ElMessage.success(res.data);
              this.getList();
              this.multipleSelection = [];
              this.checkedAll = false;
              this.$refs.multipleTableRef.clearSelection();
            } else {
            }
          })
          .catch((err) => {});
      } else {
        ElMessage.error("存在未采集数据或回填成功数据时不可操作");
      }
    },
    //导出
    exportSelect() {
      let idList = this.multipleSelection.map((item) => item.id);
      http.post("/health/exportToExcel", idList).then((res) => {
        //@ts-ignore
        if (res.code == 200) {
          //@ts-ignore
          ElMessage.success(res.message);
          this.multipleSelection = [];
          this.checkedAll = false;
          this.$refs.multipleTableRef.clearSelection();
          window.open(res.data);
        }
      });
    },
    //数据采集
    testSt() {
      const that = this;
      const upArr = [];
      this.multipleSelection.forEach((v) => {
        let cardNumber = v.cardNumber?.replace(/[\t\r].*/, "");
        let cardType = v.cardType?.replace(/[\t\r].*/, "");
        let name = v.name?.replace(/[\t\r].*/, "");
        upArr.push({
          cardNumber: cardNumber,
          cardType: cardType,
          exaTime: v.exaTime,
          // diseaseType: v.diseaseType,
          id: v.id,
          name: name,
          callType: "HealthCheckUpCollect",
          flowType: "collect",
          inputPerson: v.inputPerson,
          submitter: getUserName(),
          firstPriority: 2,
          secondPriority: 2,
        });
      });

      http
        .post("/collectAndBackFilling/submit", upArr, { timeout: 10800000 })
        .then((res) => {
          //@ts-ignore
          if (res.code === 200) {
            //@ts-ignore
            ElMessage.success(res.message);
            that.multipleSelection = [];
            this.selectionCount = 0;
            this.$refs.multipleTableRef!.clearSelection();
            this.getList();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    testDrug() {
      const that = this;
      const upArr = [];
      this.multipleSelection.forEach((v) => {
        let cardNumber = v.cardNumber?.replace(/[\t\r].*/, "");
        let cardType = v.cardType?.replace(/[\t\r].*/, "");
        let name = v.name?.replace(/[\t\r].*/, "");
        upArr.push({
          cardNumber: cardNumber,
          cardType: cardType,
          exaTime: v.exaTime,
          // diseaseType: v.diseaseType,
          id: v.id,
          name: name,
          callType: "HealthCheckUpCollect",
          flowType: "collect",
          inputPerson: v.inputPerson,
          submitter: getUserName(),
          firstPriority: 2,
          secondPriority: 2,
        });
      });

      http
        .post("/collectAndBackFilling/submit", upArr, { timeout: 10800000 })
        .then((res) => {
          //@ts-ignore
          if (res.code === 200) {
            //@ts-ignore
            ElMessage.success(res.message);
            that.multipleSelection = [];
            this.selectionCount = 0;
            this.$refs.multipleTableRef!.clearSelection();
            this.getList();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //更新his
    showUpload() {
      const upArr = [];
      const that = this;
      const multipleTrue = this.multipleSelection.every(
        (item) => item.collectStatus == "采集成功"
      );

      if (multipleTrue) {
        this.multipleSelection.forEach((v) => {
          let cardNumber = v.cardNumber?.replace(/[\t\r].*/, "");
          let cardType = v.cardType?.replace(/[\t\r].*/, "");
          let name = v.name?.replace(/[\t\r].*/, "");
          upArr.push({
            id: v.id,
            cardNumber: cardNumber,
            cardType: cardType,
            exaTime: v.exaTime,
            // diseaseType: v.diseaseType,
            name: name,
            callType: "HealthCheckUpBackFilling",
            flowType: "backFilling",
            inputPerson: v.inputPerson,
            submitter: getUserName(),
            firstPriority: 2,
            secondPriority: 2,
          });
        });

        http
          .post("/collectAndBackFilling/submit", upArr, { timeout: 10800000 })
          .then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              //@ts-ignore
              ElMessage.success(res.message);
              this.multipleSelection = [];
              this.selectionCount = 0;
              this.checkedAll = false;
              this.$refs.multipleTableRef!.clearSelection();
              this.getList();
            }
          })
          .catch((err) => {});
      } else {
        ElMessage.error("存在未采集成功或已人工回填数据不可操作");
      }
    },
    //用药情况
    showDrug() {
      const upArr = [];
      const that = this;
      const multipleTrue = this.multipleSelection.every(
        (item) => item.collectStatus == "采集成功"
      );
      console.log(multipleTrue);

      if (multipleTrue) {
        this.multipleSelection.forEach((v) => {
          let cardNumber = v.cardNumber?.replace(/[\t\r].*/, "");
          let cardType = v.cardType?.replace(/[\t\r].*/, "");
          let name = v.name?.replace(/[\t\r].*/, "");
          upArr.push({
            id: v.id,
            cardNumber: cardNumber,
            cardType: cardType,
            exaTime: v.exaTime,
            // diseaseType: v.diseaseType,
            name: name,
            callType: "MedicationBackFilling",
            flowType: "backFilling",
            inputPerson: v.inputPerson,
            submitter: getUserName(),
            firstPriority: 2,
            secondPriority: 2,
          });
        });
        http
          .post("/collectAndBackFilling/submit", upArr, { timeout: 10800000 })
          .then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              //@ts-ignore
              ElMessage.success(res.message);
              this.multipleSelection = [];
              this.selectionCount = 0;
              this.checkedAll = false;
              this.$refs.multipleTableRef!.clearSelection();
              this.getList();
            }
          })
          .catch((err) => {});
      } else {
        ElMessage.error("存在未采集成功数据不可操作");
      }
    },
    //更新辅助检查
    auxiliaryUpload() {
      const upArr = [];
      const that = this;
      const multipleTrue = this.multipleSelection.every(
        (item) => item.backFillingStatus == "回填成功"
      );

      if (multipleTrue) {
        this.multipleSelection.forEach((v) => {
          let cardNumber = v.cardNumber?.replace(/[\t\r].*/, "");
          let cardType = v.cardType?.replace(/[\t\r].*/, "");
          let name = v.name?.replace(/[\t\r].*/, "");
          upArr.push({
            id: v.id,
            cardNumber: cardNumber,
            cardType: cardType,
            exaTime: v.exaTime,
            // diseaseType: v.diseaseType,
            name: name,
            callType: "AuxiliaryExaminationBackFilling",
            flowType: "backFilling",
            inputPerson: v.inputPerson,
            submitter: getUserName(),
            firstPriority: 2,
            secondPriority: 2,
          });
        });
        http
          .post("/collectAndBackFilling/submit", upArr, { timeout: 10800000 })
          .then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              //@ts-ignore
              ElMessage.success(res.message);
              this.multipleSelection = [];
              this.selectionCount = 0;
              this.checkedAll = false;
              this.$refs.multipleTableRef!.clearSelection();
              this.getList();
            }
          })
          .catch((err) => {});
      } else {
        if (this.healthExaminationForm) {
          ElMessage.error("存在未回填或回填失败数据不可操作");
        }
      }
    },
  },
  computed: {
    //健康体检表
    healthExaminationForm() {
      if (this.formInline.backFillingType == "健康体检表") {
        return true;
      } else {
        return false;
      }
    },
    //用药情况
    medicationSituation() {
      if (this.formInline.backFillingType == "用药情况") {
        return true;
      } else {
        return false;
      }
    },
    //辅助检查
    auxiliaryInspection() {
      if (this.formInline.backFillingType == "辅助检查") {
        return true;
      } else {
        return false;
      }
    },
  },
  created() {
    this.getList();
    this.searchQuest();
  },
  watch: {
    isPopOpen: {
      handler: function () {
        if (this.isPopOpen) {
          this.searchQuest();
        }
      },
    },
  },
};
</script>
<style scoped>
.page {
  padding: 10px 20px;
  width: 100%;
  box-sizing: border-box;
}
#formbox {
  display: flex;
  flex-wrap: wrap;
  padding: 0 30px;
}
.tb {
  padding: 0 20px;
  /* overflow: hidden;
   margin-top: 2vw; */
  overflow-y: scroll;
}
.mb20 {
  /* margin: 0 20px; */
}
:deep(.el-input__wrapper) {
  width: 230px;
}
:deep(.el-form-item .el-select__wrapper) {
  min-height: 32px;
  width: 252px;
}
:deep(.el-range-editor--large.el-input__wrapper) {
  height: 32px;
  width: 232px;
}
.form-button {
  display: flex;
  justify-content: end;
}
.table-container {
  display: flex;
  flex-direction: column;
}
.table-btn {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: space-around;
}
.tr {
  text-align: right;
  height: 50px;
  line-height: 50px;
}
::v-deep .all-disabled .el-checkbox__input .el-checkbox__inner {
  display: none;
}
:deep(.el-dialog__header) {
  background-color: #016dff;
  margin: 0;
  height: 30px;
}
:deep(.el-dialog__title) {
  color: #fff;
}
:deep(.el-dialog__headerbtn .el-dialog__close) {
  color: #fff;
  font-size: 30px;
}
:deep(.el-form-item--large .el-form-item__content) {
  margin-left: 0 !important;
}
.new-pagination {
  margin: 30px 0 10px 0 !important;
}
.popover-container {
  display: flex;
  justify-content: end;
  position: relative;
}
.arrow-container {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.arrow {
  font-size: 23px;
  color: #409eff;
  margin-right: 8px;
  transition: transform 0.3s;
}

.rotate {
  transform: rotate(180deg); /* 点击后箭头旋转 */
}
.arrow-container:hover .arrow {
  color: #ff9f43; /* 悬停时箭头颜色变为橙色 */
}
.popover-item-list {
  border-radius: 10px;
  padding: 15px;
}
.popover-content-list {
  padding: 5px;
  background-color: rgba(255, 255, 255, 0.2); /* 背景透明 */
  border: 2px solid #409eff; /* 默认边框颜色 */
  border-radius: 10px;
  transition: border-color 0.3s ease; /* 边框颜色变化动画 */
}
.popover-content-list:hover {
  border-color: #ff9f43; /* 悬停时边框颜色变为橙色 */
}
.gradient-text {
  background: linear-gradient(45deg, #409eff, #ff9f43);
  -webkit-background-clip: text;
  color: transparent;
  font-weight: bold;
  transition: background 0.5s ease;
}
.popover-item {
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  height: 300px;
}
.popover-item-list {
  width: 100%;
  /* height: 250px; */
  box-sizing: border-box;
  padding: 10px;
}
.item-titel {
  margin-top: 10px;
  font-weight: 600;
  font-size: 14px;
}
.popover-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}
</style>
